﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;

namespace spaceshooter
{
    class plane
    {
        class bullet
        {
            public bullet(int x, int y, Texture2D w)
            {
                X = x;
                Y = y;
                weapon = w;
            }

            public int X, Y;
            public Texture2D weapon;
        }

        protected int X, Y;
        protected Texture2D image;
        protected Texture2D weapon;
        protected bool firing;
        List<bullet> bullets;
   
        public plane(Texture2D i)
        {
            image = i;
            X = Y = 0;
            firing = false;
            bullets = new List<bullet>();
        }

        public void draw(SpriteBatch s)
        {
            //s.Begin();
                s.Draw(image, new Vector2(X, Y), null, Color.White, 0, new Vector2(0, 0), 0.6666666666667f, SpriteEffects.None, 0);
            //s.End();
        }

        public void setPos(int x, int y)
        {
            X = x;
            Y = y;
        }

        public int getX()
        {
            return X;
        }

        public int getY()
        {
            return Y;
        }

        public Texture2D getImage()
        {
            return image;
        }

        public void setWeapon(Texture2D i)
        {
            weapon = i;
        }

        public void startFiring()
        {
            firing = true;
            bullets.Add(new bullet(X, Y, weapon));
        }

        public bool isFiring()
        {
            return firing;
        }

        public void progressShot(SpriteBatch s)
        {
            if (!firing) return;
            for (int a = 0; a < bullets.Count; a++)
            {
                s.Draw(weapon, new Vector2(bullets[a].X + (int)(.5 * image.Width) - (int)(.5 * bullets[a].weapon.Width)-12, bullets[a].Y-bullets[a].weapon.Height/2), null, Color.White, 0, new Vector2(0, 0), 0.6666666666667f, SpriteEffects.None, 0);
                bullets[a].Y -= 10;
                if (bullets[a].Y < 0) bullets.RemoveAt(a);
            }

            if (bullets.Count == 0) firing = false;
        }
    }
}
